package com.william.lifetraxer;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Dispatcher extends HttpServlet {

	public Dispatcher() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/plain;charset=UTF-8");
		
		String requestType = request.getParameter("request_type");
		
		if("log_handler".equals(requestType))
		{
			request.getRequestDispatcher("/log_handler").forward(request, response);
		}
		else if("user_handler".equals(requestType))
		{
			request.getRequestDispatcher("/user_handler").forward(request, response);
		}
		else if("info_handler".equals(requestType))
		{
			request.getRequestDispatcher("/info_handler").forward(request, response);
		}
		else if("track_handler".equals(requestType))
		{
			request.getRequestDispatcher("/track_handler").forward(request, response);
		}
		else
		{
			response.getWriter().print("VALID_REQUEST_TYPE");
		}
	}
}
